package testJdk.stream;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @version 1.0.0
 * Created by cyd on 2023-05-23 19:11:58
 * @ClassName : learn_jdk.stream.TestFilter
 * @Description : 类描述
 */
public class TestFilter {

    /**
     * 从一个集合里面筛选出另一个集合的内容
     */
    @Test
    public void testFilter() {
        ArrayList<Integer> oldList = Lists.newArrayList(2, 3, 1, 4);
        Set<Integer> set = Sets.newHashSet(2, 3);
        List<Integer> list = oldList.stream().filter(set::contains).collect(Collectors.toList());
        System.out.println(list);


        Set<Integer> set2 = Sets.newHashSet();
        List<Integer> list2 = oldList.stream().filter(set2::contains).collect(Collectors.toList());
        System.out.println(list2);

    }
}
